733B - Parade - CodeForces Solution


math *1100

Please click on ads to support us..

Python Code:

n_cols = int(input())
cols = []
l_tot = 0
r_tot = 0

for i in range(n_cols):
    l_r = input()
    l, r = l_r.split(" ")
    l = int(l)
    r = int(r)
    l_tot += l
    r_tot += r
    cols.append([l, r])

bel_in = abs(l_tot - r_tot)
max_bel = bel_in
max_k = 0

for k in range(len(cols)):
    l_tot_k, r_tot_k = l_tot, r_tot
    l_tot_k += (cols[k][1] - cols[k][0])
    r_tot_k += (cols[k][0] - cols[k][1])
    if abs(l_tot_k - r_tot_k) > max_bel:
        max_bel = abs(l_tot_k - r_tot_k)
        max_k = k + 1
    
print(max_k)

				  	     	 		  			  			   		

C++ Code:

/*
Problem: 733B
Date: 02-10-2023 08:39 PM
*/


#include <bits/stdc++.h>

#define in std::cin
#define out std::cout
#define endl std::endl
#define Max(a, b) std::max(a, b)
#define Max3(a, b, c) std::max(a, std::max(b, c))
#define Min(a, b) std::min(a, b)
#define Min3(a, b, c) std::min(a, std::min(b, c))
#define MaxE(a, b) a = std::max(a, b)
#define MinE(a, b) a = std::min(a, b)
#define Getbit(a, n) ((a >> n) & 1)
#define Bitcount(a) __builtin_popcount(a)
#define Gcd(a) __gcd(a)
#define S std::string
#define Ss std::stringstream
#define VI std::vector<int>
#define VS std::vector<std::string>
#define VPII std::vector<std::pair<int, int> >
#define VPSI std::vector<std::pair<std::string, int> >
#define VPIS std::vector<std::pair<int, std:;string> >
#define VPSS std::vector<std::pair<std::string, std::string> >
#define Mp(a, b) std::make_pair(a, b)
#define PII std::pair<int, int>
#define PSI std::pair<std::string, int>
#define PIS std::pair<int, std::string>
#define PSS std::pair<std::string, std::string>
#define SI std::set<int>
#define SS std::set<std::string>
#define SPII std::set<std::pair<int, int> >
#define SPSI std::set<std::pair<std::string, int> >
#define SPIS std::set<std::pair<int, std::string> >
#define SPSS std::set<std::pair<std::string, std::string> >
#define VII std::vector<int>::iterator
#define VSI std::vector<std::string>::iterator
#define VPIII std::vector<std::pair<int, int> >::iterator
#define VPISI std::vector<std::pair<int, std::string> >::iterator
#define VPSII std::vector<std::pair<std::string, int> >::iterator
#define VPSSI std::vector<std::pair<std::string, std::string> >::iterator
#define MsI std::multiset<int>
#define MsS std::multiset<std::string>
#define SII std::set<int>::iterator
#define SPIII std::set<std::pair<int, int> >::iterator
#define SPSII std::set<std::pair<std::string, int> >::iterator
#define SPISI std::set<std::pair<int, std::string> >::iterator
#define SPSSI std::set<std::pair<std::string, std::string> >::iterator
#define MsII std::multiset<int>::iterator
#define MsSI std::multiset<std::string>::iterator
#define MapII std::map<int, int>
#define MapSS std::map<std::string, std::string>
#define MapIS std::map<int, std::string>
#define MapSI std::map<std::string, int>

int n, l, r;
int amt[100000];
int tot;
int max, maxdex;

int main() {
	in >> n;
	for(int i = 0; i < n; i++) {
		in >> l >> r;
		amt[i] = r - l;
		tot += amt[i];
	}
	max = abs(tot);
	for(int i = 0; i < n; i++) {
		if(abs(tot - 2 * amt[i]) > max) {
			max = abs(tot - 2 * amt[i]);
			maxdex = i + 1;
		}
	}
	out << maxdex;
}


Comments

Submit
0 Comments
More Questions

237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes